package com.zhongyu.base.provider.apiimpl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zhongyu.base.provider.mapper.ImageMapper;
import com.zhongyu.base.provider.pojo.Image;
import com.zhongyu.comm.api.ImageApi;
import com.zhongyu.comm.vo.DmImage;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class ImageApiImpl implements ImageApi {

    @Resource
    private ImageMapper imageMapper;

    private DmImage transform(Image image){
        DmImage dmImage =new DmImage();
        BeanUtils.copyProperties(image,dmImage);
        return dmImage;
    }

    @Override
    public DmImage findOne(Integer targetId, Integer type, Integer category) {
        QueryWrapper<Image> queryWrapper = Wrappers.query();
        queryWrapper.eq("target_id",targetId)
                .eq("type",type)
                .eq("category",category);
        return this.transform(imageMapper.selectOne(queryWrapper));
    }
}
